package com.medicine.product.fengin;

import org.springframework.http.HttpStatus;

/**
 * 项目名称：ChildProtectionSystem
 * 包名称:com.vdf.pms.common.http
 * 类描述：
 * 创建人：hejian
 * 创建时间：2020-04-01 17:04
 * 修改人：hejian
 * 修改时间：2020-04-01 17:04
 * 修改备注：
 *
 * @author hejian
 */
public class ResponseResult<T> {

	private int code;

	private T data;

	private String msg;

	public ResponseResult() {

	}

	public ResponseResult(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public ResponseResult(int code, T data, String msg) {
		this.code = code;
		this.data = data;
		this.msg = msg;
	}

	public static <T> ResponseResult<T> build(T data) {
		ResponseResult<T> result = new ResponseResult<T>();
		result.setData(data);
		return result;
	}

	@SuppressWarnings("unchecked")
	public static <T> ResponseResult<T> build() {
		ResponseResult result = new ResponseResult<>();
		return (ResponseResult<T>) result;
	}

	@SuppressWarnings("unchecked")
	public <E> ResponseResult<E> success() {
		this.code = HttpStatus.OK.value();
		this.msg = HttpStatus.OK.getReasonPhrase();
		return (ResponseResult<E>) this;
	}

	@SuppressWarnings("unchecked")
	public <E> ResponseResult<E> fail() {
		this.code = 3000;
		this.msg = "操作失败！";
		return (ResponseResult<E>) this;
	}

	@SuppressWarnings("unchecked")
	public <E> ResponseResult<E> fail(String msg) {
		this.code = 3000;
		this.msg = msg;
		return (ResponseResult<E>) this;
	}

	@SuppressWarnings("unchecked")
	public <E> ResponseResult<E> empty() {
		this.code = HttpStatus.OK.value();
		this.data = null;
		this.msg = "查询到的结果为空！";
		return (ResponseResult<E>) this;
	}


	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
